package com.learning.security.controller;

import com.learning.security.controller.vo.AdminUserRespVO;
import com.learning.security.controller.vo.UserSaveReqVO;
import com.learning.security.service.AdminUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/user")
public class AdminUserController {

    @Autowired
    private AdminUserService adminUserService;

    @PostMapping("/create")
    public Long createUser(@RequestBody UserSaveReqVO userSaveReqVO) {
        Long id = adminUserService.createUser(userSaveReqVO);
        return id;
    }

    @PostMapping("/get")
    public AdminUserRespVO getUser(@RequestParam Long userId) {
        AdminUserRespVO adminUserRespVO = new AdminUserRespVO();
        BeanUtils.copyProperties(adminUserService.getUser(userId), adminUserRespVO);
        return adminUserRespVO;
    }

    @PostMapping("/assignRole")
    public boolean assignRole(Long userId, Long roleId) {
        return adminUserService.assignRole(userId, roleId);
    }

}
